<template>
	<view class="living-container">
		<!-- 直播画面 -->
		<view class="live-video-container">
			<image class="live-video" :src="liveData.cover" mode="aspectFill"></image>

			<!-- 顶部信息栏 -->
			<view class="live-header">
				<view class="header-left">
					<text class="room-title">唠叨的直播间</text>
					<text class="room-status">一般</text>
				</view>
				<view class="header-right">
					<text class="live-status-text">直播状态</text>
				</view>
			</view>
		</view>

		<!-- 聊天区域 -->
		<view class="chat-container">
			<scroll-view class="chat-messages" scroll-y="true" :scroll-top="scrollTop">
				<view class="chat-message" v-for="(message, index) in chatMessages" :key="index">
					<view class="message-user">
						<text class="username" :style="{color: message.color}">{{ message.username }}</text>
						<text class="content">: {{ message.content }}</text>
					</view>
				</view>
			</scroll-view>

			<!-- 输入区域 -->
			<view class="chat-input-area">
				<input class="chat-input" v-model="chatInput" placeholder="说点什么..." @confirm="sendMessage" />
				<view class="input-functions">
					<text class="function-text">分享</text>
					<text class="function-text">更多</text>
					<button class="end-btn">结束</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				liveData: {
					cover: '/static/live-bg.jpg' // 示例背景图
				},
				chatMessages: [{
						username: 'free',
						content: 'hello',
						color: '#FFD700'
					},
					{
						username: 'Miracle',
						content: '讲的很专业',
						color: '#42B983'
					},
					{
						username: 'WRR',
						content: '喜欢您您的课程',
						color: '#FF6B6B'
					},
					// 更多消息...
				],
				chatInput: '',
				scrollTop: 0
			}
		},
		methods: {
			sendMessage() {
				if (!this.chatInput.trim()) return;

				this.chatMessages.push({
					username: '我',
					content: this.chatInput,
					color: '#FFD700'
				});

				this.chatInput = '';
				this.scrollToBottom();
			},
			scrollToBottom() {
				this.$nextTick(() => {
					this.scrollTop = 99999;
				});
			}
		}
	}
</script>

<style>
	.living-container {
		position: relative;
		width: 100%;
		height: 100vh;
		background-color: #000;
	}

	.live-video-container {
		position: relative;
		width: 100%;
		height: 70vh;
	}

	.live-video {
		width: 100%;
		height: 100%;
	}

	/* 顶部信息栏样式 */
	.live-header {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx 30rpx;
		z-index: 10;
	}

	.header-left {
		display: flex;
		flex-direction: column;
	}

	.room-title {
		color: #fff;
		font-size: 32rpx;
		font-weight: bold;
	}

	.room-status {
		color: #999;
		font-size: 24rpx;
		margin-top: 5rpx;
	}

	.live-status-text {
		color: #fff;
		font-size: 24rpx;
	}

	/* 聊天区域样式 */
	.chat-container {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		height: 30vh;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		flex-direction: column;
	}

	.chat-messages {
		flex: 1;
		padding: 20rpx;
		overflow-y: auto;
	}

	.chat-message {
		margin-bottom: 15rpx;
	}

	.message-user {
		display: flex;
	}

	.username {
		font-size: 26rpx;
		margin-right: 10rpx;
	}

	.content {
		font-size: 26rpx;
		color: #fff;
	}

	/* 输入区域样式 */
	.chat-input-area {
		display: flex;
		padding: 20rpx;
		border-top: 1rpx solid rgba(255, 255, 255, 0.1);
	}

	.chat-input {
		flex: 1;
		height: 70rpx;
		background-color: rgba(255, 255, 255, 0.2);
		border-radius: 35rpx;
		padding: 0 30rpx;
		font-size: 26rpx;
		color: #fff;
	}

	.input-functions {
		display: flex;
		align-items: center;
		margin-left: 20rpx;
	}

	.function-text {
		color: #FFD700;
		font-size: 26rpx;
		margin-left: 20rpx;
	}

	.end-btn {
		background: none;
		border: none;
		color: #FF4E4E;
		font-size: 26rpx;
		padding: 0;
		margin-left: 20rpx;
	}
</style>